
{% extends "data_opform.html" %}
{% load i18n %}
{% block form %}
{% autoescape off %}
<table class = "tbl_data_edit"  cellpadding="3px">
    <tr class="displayN">
        {{form.commkey|field_as_td_h}}
    </tr>
    <tr class="displayN">
        {{form.commkey_again|field_as_td_h}}
    </tr>
	<tr id="tr_old_pwd">
		<th><label>{%trans "旧密码"%}:</label></th>
        <td><input type="password" id="id_old_commpwd" onblur="check_commpwd()"/>
        &nbsp;<a id="valid_commpwd" href="javascript:void(0)" onclick="check_commpwd()">{% trans "验证" %}</a>&nbsp;&nbsp;&nbsp;<span id="r_msg"></span></td>
	</tr>
	<tr id="tr_new_pwd">
        <th><label>{%trans "新密码"%}:</label></th>
        <td><input type="password" id="id_new_commpwd" maxlength="15"/>
	</tr>
	<tr id="tr_conf_pwd">
        <th><label>{%trans "确认密码"%}:</label></th>
        <td><input type="password" id="id_conf_commpwd" maxlength="15" />
        <span id="e_msg2"></span></td>
		
	</tr>
</table>
{% if form.non_field_errors %}
			<tr><td>{{ form.non_field_errors }}</td></tr>
		{% endif %}

{% endautoescape %}
{% endblock %}

{% block loading %}

{% endblock %}

{% block addjs %}
	{% if request.user|HasPerm:"iclock.resetpassword_device" %}
    $("#id_new_commpwd").attr("disabled","disabled");
    $("#id_conf_commpwd").attr("disabled","disabled");

    var dev_id = 0;
    $(".select_row").each(function(){
    	if($(this).attr("checked"))
    	{
    		dev_id = $(this).parents("tr").attr("data");
    	}
    });
    
    //验证旧的通讯密码是否正确
    var check_old_commpwd = false;
    function check_commpwd(){
        var old_commpwd=$("#id_old_commpwd").val();
        $.post(
            "/iclock/tasks/check_old_commpwd/",
            {"old_commpwd":old_commpwd,"device":dev_id},
            function(xml){
                if(xml == 'ok')
                {
                    $("#r_msg").html('<label class="gray">{%trans "正确"%}</label>');
                    check_old_commpwd = true;
                    $("#id_new_commpwd").attr("disabled","");
                    $("#id_conf_commpwd").attr("disabled","");
                }else
                {
                    $("#r_msg").html("<font color='red'>{%trans "错误"%}</font>");
                    check_old_commpwd = false;
                    $("#id_new_commpwd").attr("disabled","disabled");
                    $("#id_conf_commpwd").attr("disabled","disabled");
                }
            }
        );
    }
    	
    var before_submit = function()
	{
        var v1 = $("#id_new_commpwd").val();
        var v2 = $("#id_conf_commpwd").val();
		if(v1 == v2&check_old_commpwd)
        {
            $("#id_commkey").val(v1);
            $("#id_commkey_again").val(v2);
            return true;
        }
        else if(v1 != v2)
        {
            var html="<font color='red'>{%trans '密码必须一致'%}</font>"
            $("#e_msg2").html(html);
            $("#id_new_commpwd").attr("value","");
            return false;
        }
    }

	var after_cancel = function()
	{
		$("#id_datalist").get(0).g.load_data();
		after_cancel = undefined;//加载数据后取消
	}
        
	{% else %}
		alert(gettext("对不起,您没有访问该页面的权限,不能浏览更多信息！"));
		window.location.href = "/{{ request.surl }}accounts/login/";
	{% endif %}<!-- iclock.opchangeipofacpanel_device -->
{% endblock%}
